package edu.xpu.compute.recommend.dataGenerator;

import java.text.DecimalFormat;
import java.util.Date;
import java.util.Random;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import edu.xpu.compute.recommend.entity.SysBook;
import edu.xpu.compute.recommend.service.SysBookService;

@Component
public class SysBookDataGenerator {
	
	public static String[] PUBLISH_HOUSE = new String[]{
		"机械工业出版社", "清华大学出版社", "人民邮电出版社", "电子工业出版社"
	};
	
	public static String[] BOOK_TYPE = new String[]{
		"文史类", "理工类"
	};

	@Autowired
	private SysBookService bookService;
	
	public void bookGenerator() {
		Random random = new Random();
		Date currentDate = new Date();
		DecimalFormat df = new DecimalFormat("000");
		int publishLen = PUBLISH_HOUSE.length;
		int bookTypeLen = BOOK_TYPE.length;
		for (int i = 0; i < 300; i++) {
			SysBook sysBook = new SysBook();
			sysBook.setName("图书"+df.format(i));
			sysBook.setCreateDate(currentDate);
			sysBook.setBookType(BOOK_TYPE[random.nextInt(bookTypeLen)]);
			sysBook.setPrice(random.nextFloat() * (100 - 80) + 80);
			sysBook.setBookStandardNumber("NO.2019"+df.format(i));
			sysBook.setPublishingHouse(PUBLISH_HOUSE[random.nextInt(publishLen)]);
			bookService.save(sysBook);
		}
	}
}
